<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/29 0029
 * Time: 16:03
 */

namespace app\home\controller;
use think\Db;
use think\Paginator;


class Zphome extends Base
{
        public function index($id=0){
            session('cg_id',null);
            session('getid',2);
            session('venue_id',null);
            session('style_id',null);
            //轮播图
            $data_banner = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and class_id=34')->order('sort desc,id desc')->field('banner_img,out_link')->select();
            $this->assign('data_banner',$data_banner);
            //选择
            if($id!=0){
//                $id= input('param.id');
                session('getid',$id);
                $where=[
                    'z.is_del'=>0,
                    'z.is_show'=>1,
                    'z.sign'=>"pc",
                    's.sign'=>"pc",
                    'j.sign'=>"pc",
                    's.id'=>$id
                ];
                $data_zp = Db::name('zp')->alias('z')->join('style s','z.style_id=s.id')
                    ->join('jd j','z.cg_id=j.id')
//                    ->where('z.is_del=0 and z.is_show=1 and z.sign="pc" and s.sign="pc" and j.sign="pc"')
                    ->where($where)
                    ->order('z.sort desc,z.id desc')
                    ->field('z.title,z.id as zjd,z.main_img,z.click,s.id,s.name,s.sort,j.id,j.name as jname')
                    ->paginate(16,false,['query' => request()->param()]);
                $page = $data_zp->render();
                $this->assign('page', $page);
            }else{
                $data_zp = Db::name('zp')->alias('z')->join('style s','z.style_id=s.id')
                 ->join('jd j','z.cg_id=j.id')->where('z.is_del=0 and z.is_show=1 and z.sign="pc" and s.sign="pc" and j.sign="pc" ')
                 ->order('z.sort desc,z.id desc')
                 ->field('z.title,z.id as zjd,z.main_img,z.click,s.id,s.name,s.sort,j.id,j.name as jname')
                 ->paginate(16,false,['query' => request()->param()]);
                $page = $data_zp->render();
                $this->assign('page', $page);
            }
            $this->assign('data_zp',$data_zp);
//            $data_style
            //选择场馆
            $data_venue = Db::name('venue')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->field('name,id')->select();
            $this->assign('data_venue',$data_venue);
            //选择风格
            $data_style = Db::name('style')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->field('name,id,sort')->limit(4)->select();

            $this->assign('data_style',$data_style);
            $this->assign('data_seo',getColumnseo(3));

            //作品
//            $data = Db::name('zp')->where($where)->order('sort desc,id desc')->field('title,id,main_img,ps_time')->limit(8)->select();
//            $data_next= Db::name('zp')->where($where)->order('sort desc,id desc')->field('title,id,main_img,ps_time')->page(2,8)->select();
//            $type = 1;
//            if(!$data_next){
//                $type = 2;
//            }
//            $this->assign('type',$type);
//            $this->assign('data',$data);
            //场馆基地(顶部导航推荐)
            $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
            $this->assign('data_cg',$data_cg);
            $this->assign('data_seo',getColumnseo(3));
            return $this->fetch();
        }

   public function details($id=0,$nid=0,$pid=0){

$this->publicIndex();

        if(!empty($id)){

            $where['id']=$id;

            $where = [

                'sign'=>"pc",
                'id'=>$id,
                'is_show'=>1,
                'is_del'=>0

            ];

            $data_kp = Db::name('zp') ->where($where)

                ->order('sort desc,id desc')

                ->find();

            $this->assign('data_kp',$data_kp);

        }else{

            return json(['code'=>0,'msg'=>'非法请求']);

        }

        //底部详情也广告

        $data_bannerfont = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and class_id=41')

            ->order('sort desc,id desc')->field('banner_img,out_link')->find();

        $this->assign('data_bannerfont',$data_bannerfont);

        //推荐客片

        $where = [

            'a.sign'=>"pc",

            'a.is_show'=>1,

            'a.is_del'=>0

        ];

        $data_kplist = Db::name('psjd')->alias('a')

            ->where($where)

            ->order('a.sort asc')

            ->paginate(12);

        $this->assign('data_kplist',$data_kplist);

        return $this->fetch();

    }



        //客照内容
        public function fg(){
            $id = intval(input('param.id'));
            if($id){
                $data = Db::name('zp')->where('id',$id)->find();
                if($data['works_photo'] !==''){
                    $imgurl = Db::name('works_pic')->where('pic_id','in',$data['works_photo'])->select();
                    $data['imgurl']=$imgurl;
                }
                $this->assign('data',$data);
                //上一组
                $upId = Db::name('zp')->where('id','<',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id desc')->limit(1)->value('id');
                $this->assign('upId',$upId);
                //下一组
                $downId = Db::name('zp')->where('id','>',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id asc')->limit(1)->value('id');
                $this->assign('downId',$downId);
            }
            //活动推荐
            $hd = Db::name('activity')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->limit(2)->field('id,main_img')->select();
            $this->assign('hd',$hd);
            //场馆基地(顶部导航推荐)
            $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
            $this->assign('data_cg',$data_cg);
            $this->assign('data_seo',getColumnseo(3));
             return $this->fetch();
        }

    public  function  getmore()
    {
        $cg_id = intval(input('post.cg_id'));
        $venue_id = intval(input('post.venue_id'));
        $style_id = intval(input('post.style_id'));
        $where = 'is_del=0 and is_show=1 and sign="pc"';
        $page = intval(input('post.page'));
        //广告
        if($cg_id){
            $where .=' and cg_id = '.$cg_id;
        }
        if($style_id){
            $where .=' and style_id = '.$style_id;
        }
        if($venue_id){
            $where .=' and venue_id = '.$venue_id;
        }

        $data = Db::name('zp')->where($where)->field("id,title,main_img,ps_time")->page($page,8)->select();
        $next_data = Db::name('zp')->where($where)->order('sort desc,id desc')->field('title,id,main_img,ps_time')->page($page+1,8)->select();
        $type = 1;
        if(!$next_data){
            $type = 2;
        }
        if ($data) {
            return json(['code' => 1, 'data' => $data,'type'=>$type]);
        } else {
            return json(['code' => 0, 'msg' => '没有更多了']);
        }
    }


}